<?php
/*
本系统由苏酷伊基于SiteHub项目二次开发
作者博客： https://www.sukuy.com/
后续更新地址： https://www.sukuy.com/navigation
作者QQ：3288637559
QQ交流群：884250547
任何第三方非官网在发布本系统时，不得删除该注释、版权信息、作者信息及官网等内容
*/
define('IN_ADMIN', true);
include("../includes/common.php");
if ($admin_islogin == 1) {
} else exit("<script language='javascript'>window.location.href='./login.php';</script>");

$act = _get('act');
switch ($act) {
    case 'reject':
        @header('Content-Type: application/json; charset=UTF-8');
        $id = _post('id');
        if (!$id) {
            exit('{"code":-1,"msg":"id不能为空！"}');
        }
        
        $apply_info = $DB->find('apply', 'name', array('id' => $id));
        $apply_name = $apply_info ? $apply_info['name'] : '未知申请';
        $result = $DB->update('apply', array('reject' => '1'), array('id' => $id));
        if ($result) {
            
            add_action_log($conf['admin_user'], '拒绝申请(ID: ' . $id . ')：' . $apply_name, 1);
            exit('{"code":0,"msg":"拒绝申请，放进黑名单成功！"}');
        }
        
        add_action_log($conf['admin_user'], '拒绝申请失败(ID: ' . $id . ')：' . $apply_name, 0);
        exit('{"code":-1,"msg":"拒绝申请失败！"}');
        break;
    case 'reset':
        @header('Content-Type: application/json; charset=UTF-8');
        $id = _post('id');
        if (!$id) {
            exit('{"code":-1,"msg":"id不能为空！"}');
        }
        
        $apply_info = $DB->find('apply', 'name', array('id' => $id));
        $apply_name = $apply_info ? $apply_info['name'] : '未知申请';
        $result = $DB->update('apply', array('reject' => '0'), array('id' => $id));
        if ($result) {
            
            add_action_log($conf['admin_user'], '恢复审核申请(ID: ' . $id . ')：' . $apply_name, 1);
            exit('{"code":0,"msg":"恢复审核申请成功！"}');
        }
        
        add_action_log($conf['admin_user'], '恢复审核申请失败(ID: ' . $id . ')：' . $apply_name, 0);
        exit('{"code":-1,"msg":"恢复审核申请失败！"}');
        break;
    case 'del':
        @header('Content-Type: application/json; charset=UTF-8');
        $id = _post('id');
        if (!$id) {
            exit('{"code":-1,"msg":"id不能为空！"}');
        }
        
        $apply_info = $DB->find('apply', 'name', array('id' => $id));
        $apply_name = $apply_info ? $apply_info['name'] : '未知申请';
        $result = $DB->delete('apply', array('id' => $id));
        if ($result) {
            
            add_action_log($conf['admin_user'], '删除申请(ID: ' . $id . ')：' . $apply_name, 1);
            exit('{"code":0,"msg":"删除成功！"}');
        }
        
        add_action_log($conf['admin_user'], '删除申请失败(ID: ' . $id . ')：' . $apply_name, 0);
        exit('{"code":-1,"msg":"删除失败！"}');
        break;
    case 'view':
        @header('Content-Type: application/json; charset=UTF-8');
        $id = _post('id');
        if (!$id) {
            exit('{"code":-1,"msg":"id不能为空！"}');
        }
        $apply = $DB->find('apply', '*', array('id' => $id));
        if (empty($apply)) {
            
            add_action_log($conf['admin_user'], '查看不存在的申请(ID: ' . $id . ')', 0);
            exit('{"code":-1,"msg":"申请不存在！"}');
        }
        
        add_action_log($conf['admin_user'], '查看申请(ID: ' . $id . ')：' . $apply['name'], 1);
        
        $data = array(
            'code' => 0,
            'id' => $apply['id'],
            'name' => $apply['name'],
            'catename' => $apply['catename'],
            'url' => $apply['url'],
            'keywords' => $apply['keywords'],
            'introduce' => $apply['introduce'],
            'favicon' => $apply['favicon'] ?: $apply['img'],
            'link_location' => $apply['link_location'] ?: '未填写',
            'contact' => $apply['contact'] ?: '未填写',
            'icp' => $apply['icp'] ?: '未填写',
            'create_time' => $apply['create_time']
        );
        exit(json_encode($data, JSON_UNESCAPED_UNICODE));
        break;
    default:
        exit('{"code":-4,"msg":"No Act"}');
        break;
}
